home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Eagles Nest BBS 8
/
Eagles_Nest_Mac_Collection_Disc_8.TOAST
/
Developer Tools⁄Additions
/
MacTCPToolBx
/
Source Code ƒ
/
TCPActiveOpen.p
< prev
next >
Wrap
Text File
|
1989-06-01
|
3KB
|
117 lines
(*
TCPActiveOpen(remoteIP,remotePort,localPort) -- Open a TCP connection to the socket specified, and
return a connection ID.
To compile and link this file using Macintosh Programmer's Workshop,
pascal -w TCPActiveOpen.p
link -m ENTRYPOINT -o HyperCommands -rt XFCN=7860 -sn Main=TCPActiveOpen ∂
TCPActiveOpen.p.o "{Libraries}HyperXLib.o" "{MPW}"Libraries:interface.o
© Copyright 1988 by Apple Computer, Inc.
Initial coding 12/88 by Harry R. Chesley.
*)
{$R-}
{$S TCPActiveOpen } { Segment name must be the same as the command name. }
unit DummyUnit;
interface
uses MemTypes, QuickDraw, OSIntf, HyperXCmd;
procedure EntryPoint(paramPtr: XCmdPtr);
implementation
procedure TCPActiveOpen(paramPtr: XCmdPtr); forward;
procedure EntryPoint(paramPtr: XCmdPtr);
begin
TCPActiveOpen(paramPtr);
end;
procedure TCPActiveOpen(paramPtr: XCmdPtr);
var remoteIP: longInt; { IP address of desintation. }
remotePort: integer; { Port address of destination. }
localPort: integer; { Port address on our side. }
dummy: integer;
resultStr: str255;
procedure Fail(errMsg: Str255); { set theResult and quit }
begin
paramPtr^.returnValue := PasToZero(paramPtr,errMsg);
exit(TCPActiveOpen);
end;
{$I TCPUtil.inc}
procedure FailAndDispose(errMsg: Str255);
begin
DisposPtr(Ptr(Connection));
Fail(errMsg)
end;
procedure createStream;
{ Make a new stream. }
begin
{ Allocate our connection block, and fill it in. }
Connection := TCPConnectionPtr(NewPtr(sizeof(TCPConnectionType)));
if Connection = nil then Fail('§§§ buffer allocation failed §§§');
Connection^.magic := MAGICNUMBER;
Connection^.incomingSize := 0;
{ Open the driver. }
if OpenDriver('.IPP',SyncControlBlock.ioCRefNum) <> noErr then
FailAndDispose('§§§ driver open failed §§§');
{ Create a stream. }
ZeroIOParms;
PutControlLongAtOffset(ord4(@Connection^.buffer),32);
PutControlLongAtOffset(TCPBUFFERSIZE,36);
SyncControlBlock.csCode := TCPcsCreate;
if PBControl(@SyncControlBlock,false) <> noErr then
FailAndDispose('§§§ stream creation failed §§§');
Connection^.asyncControlBlock := SyncControlBlock;
end;
begin
if (paramPtr^.paramCount <> 2) and (paramPtr^.paramCount <> 3) then
Fail('§§§ parameter count is not 2 or 3 §§§');
remoteIP := GetLongParm(1); { First parameter is the remote IP address. }
remotePort := GetLongParm(2); { Second parameter is the remote port number. }
if paramPtr^.paramCount = 3 then localPort := GetLongParm(3) {Third parameter is the local port #. }
else localPort := 0; { ... which is optional. }
{ Make a new stream. }
createStream;
{ Issue an active open. }
ZeroIOParms;
PutControlLongAtOffset(remoteIP,36);
PutControlWordAtOffset(remotePort,40);
PutControlWordAtOffset(localPort,46);
SyncControlBlock.csCode := TCPcsActiveOpen;
with Connection^ do
begin
asyncControlBlock := SyncControlBlock;
if PBControl(@asyncControlBlock,true) <> noErr then
begin
ZeroIOParms;
SyncControlBlock.csCode := TCPcsRelease;
dummy := PBControl(@SyncControlBlock,false);
FailAndDispose('§§§ connection open failed §§§');
end;
end;
LongToStr(paramPtr,Ord4(Connection),resultStr);
paramPtr^.returnValue := PasToZero(paramPtr,resultStr)
end;
end.